// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import axios from './libs/axios';
const openIdUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token'
cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () { 
        this.getOpenid();
    },

    // update (dt) {},

    createRoom(){
        cc.log("发送创建房间get请求");
        cc.log(axios);
        axios.get( {
            url: "http://localhost:8080/create/room",
        }).then((res)=>{
            console.log(res);
        }).catch(err=>console.log(err))
    },

    toCompete(){

    },

    getOpenid(){
        wx.login({
            success (res) {
              if (res.code) {
                //发起网络请求
                wx.request({
                    url: 'http://localhost:8080/testopenid',
                    data: {
                        code: res.code
                    },
                    success(openId){
                        console.log(openId.data);
                        this.openId = openId.data;
                    },
                    fail(){  
                        console.log('fail')
                    },
                })
            }
            else {
                console.log('登录失败！' + res.errMsg)
              }
            }
          })
    }


});
